<?php
class EditVip extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		$me = check_login ( ADMIN_LOGIN_PAGE );
		$uid = irqst ( 'uid' );
		if (empty ( $uid )) {
			Response::errorPage ( "<strong>出错啦!</strong>uid为空，系统无法加载对应会员账户。", $this->referer );
		} else {
			$user = sess_del ( 'vip_form_info', false );
			if (! $user) {
				$userModel = new VipUserModel ();
				$user = $userModel->read ( $uid );
			}
			if ($user == false) {
				Response::errorPage ( "<strong>出错啦!</strong>uid为{$uid}的用户不存在。", $this->referer );
			} else {
				$data = $user;
				$data ['vip'] = $user;
				$data ['page_tip_info'] = sess_del ( 'page_tip_info' );
			}
		}
		$gM = new CoreGroupModel ();
		$groups = $gM->where ( array ('type' => 'vip' ) )->select ();
		$data ['groups'] = $groups;
		if ($groups) {
			$data ['group_options'] = $groups->toArray ( 'gname', 'name', array ('' => '请选择会员组' ) );
		} else {
			$data ['group_options'] = array ('' => '请选择会员组' );
		}
		
		bind ( 'get_editvip_tpl', array ($this, 'get_editvip_tpl' ), 1, 2 );
		
		$data ['alert_cls'] = 1 == irqst ( 'suc', 0 ) ? 'alert-success' : 'alert-error';
		$data ['error'] = sess_del ( 'vip_form_error', array () );
		$data ['error_cls'] = ModelValidator::getErrorCls ( $data ['error'] );
		$data ['group'] = rqst ( 'group', 'base' );
		$data ['vip_groups'] = apply_filter ( 'get_editvip_group', array ('base' => '基本资料' ) );
		$data ['editvip_tpl'] = apply_filter ( 'get_editvip_tpl', '', $data ['group'] );
		$data = apply_filter ( 'get_editvip_data', $data );
		return new SmartyView ( $data, 'vip/EditVip' );
	}
	
	public function get_editvip_tpl($tpl, $group) {
		if ($group == 'base') {
			return 'core/views/vip/EditVipBase.tpl';
		}
		return '';
	}
}